﻿using Ewell.BizComponent.UI.Core.VievModel;
using Ewell.BizComponent.UI.OutSetl.ViewModel;
using Ewell.Interface.Common.Model.Common;
using Ewell.Interface.Common.Model.GateWay.Dto.Dict;
using Ewell.Interface.Common.Model.GateWay.GateWayUriInfo;
using Ewell.Interface.Common.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;

namespace Ewell.BizComponent.UI.OutSetl.Views
{
    /// <summary>
    /// OutSettlementView.xaml 的交互逻辑
    /// </summary>
    public partial class OutSettlementView : UserControl
    {
        public static readonly DependencyProperty OutSettlementVmProperty = DependencyProperty
            .Register("outSettlementVm", typeof(OutSettlementVm), typeof(OutSettlementView),
            new FrameworkPropertyMetadata(new OutSettlementVm()));
        public OutSettlementVm outSettlementVm
        {
            get
            {
                if (this.DataContext.GetType() != typeof(OutSettlementVm))
                    return (OutSettlementVm)GetValue(OutSettlementVmProperty);
                else
                    return this.DataContext as OutSettlementVm;
            }
            set { SetValue(OutSettlementVmProperty, value); }
        }
        public OutSettlementView()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if(outSettlementVm==null) outSettlementVm=new OutSettlementVm();
            #region 查询医保费别
            DictPatientTypeDubboService dictPatientTypeDubboService = new DictPatientTypeDubboService();
            var gateWayResult = dictPatientTypeDubboService.queryPagePatientType.Post<List<PatientTypeVm>>(new DictPatientTypeQueryRequest
            {
                athenaMenuId = LoginInfo.menuId,
                enabledFlag = "1",
            }).CheckSuccess("HISBIZ");
            this.outSettlementVm.patientTypeList = gateWayResult.@object;
            if (this.outSettlementVm.patient != null && this.outSettlementVm.selectedPatientType == null)
            {
                this.outSettlementVm.selectedPatientType = this.outSettlementVm?.patientTypeList?.FirstOrDefault(f => f.no == this.outSettlementVm?.patient?.patientTypeNo);
                if (this.outSettlementVm.selectedPatientType == null)
                    this.outSettlementVm.selectedPatientType = this.outSettlementVm?.patientTypeList?.FirstOrDefault();
            }
            #endregion
            outSettlementVm.LoadRecipel.Execute(this.outSettlementVm);
            this.DataContext = outSettlementVm;
        }
    }
}
